//
//  Status.swift
//  WeiBlog
//
//  Created by apple on 15/10/20.
//  Copyright © 2015年 xiang. All rights reserved.
//

import UIKit

/// 微博内容
class Status: NSObject {
    
    ///  用户自己(谁发的微博)
    var user:UserInfo?
    // id很重要,一条微博对应一个id,越后创建的微博id越大,也就是时间越近(这个在刷新哪里要考虑到)
    var id:Int = 0
    ///  该条微博创建时间
    var created_at:String?
    ///  微博正文
    var text:String?
    ///  来源
    var source:String?
    ///  被转发的原微博信息字段，当该微博为转发微博时返回
    var retweeted_status:Status?
    //注意这是一个存放字典的数组,那么我们需要的是什么,是value(也就是每一个图片的URL字符串)
    ///  图片数组(图片的URL是以字典的形式存在数组中的,通过key能得到URL)
    var pic_urls:[[String:String]]?
    ///  字典转模型
    init(dict:[String:AnyObject]){
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
        //在这要考虑一个问题,每条微博数据里面会包含一个用户信息,也是一个字典,也就是这里要考虑模型嵌套
    }
    
    //setValuesForKeysWithDictionary(dict)的本质就是调用这个方法
    override func setValue(value: AnyObject?, forKey key: String) {
        
        //判断是否是user(当在字典转模型的时候,如果某个key对应的value是字典,那么会将这个key的类型转成字典,然后赋值)
        
        if key == "user"{
            let userDict = value as? [String:AnyObject]
            
            user = UserInfo(dict: userDict!)
            
            return
        }
        
        if key == "retweeted_status"{
            
            let statusDict = value as? [String:AnyObject]
            
            retweeted_status = Status(dict: statusDict!)
            
            return
        }
         super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    override var description:String{
        
        let keys = ["user","id","created_at","text","source","pic_urls","retweeted_status"]
        
        return "\(dictionaryWithValuesForKeys(keys))"
    }

}

//"pic_urls": (
//{
//"thumbnail_pic" = "http://ww3.sinaimg.cn/thumbnail/006aewtbgw1ex7mpm6p83j30ku0kuq8k.jpg";
//},
//{
//"thumbnail_pic" = "http://ww3.sinaimg.cn/thumbnail/006aewtbgw1ex7mpn3b1lj30m80m8qac.jpg";
//},
//{
//"thumbnail_pic" = "http://ww3.sinaimg.cn/thumbnail/006aewtbgw1ex7mpo2ur0j30m80m8n51.jpg";
//},
//{
//"thumbnail_pic" = "http://ww4.sinaimg.cn/thumbnail/006aewtbgw1ex7mpoxzndj30m80m8jww.jpg";
//},
//{
//"thumbnail_pic" = "http://ww3.sinaimg.cn/thumbnail/006aewtbgw1ex7mpppfg7j30m80m8454.jpg";
//},
//{
//"thumbnail_pic" = "http://ww1.sinaimg.cn/thumbnail/006aewtbgw1ex7mprv6z8j30m80m8466.jpg";
//},
//{
//"thumbnail_pic" = "http://ww1.sinaimg.cn/thumbnail/006aewtbgw1ex7mpsqqrnj30m60m8wjs.jpg";
//},
//{
//"thumbnail_pic" = "http://ww1.sinaimg.cn/thumbnail/006aewtbgw1ex7mpunjqkj31kw1kw7km.jpg";
//},
//{
//"thumbnail_pic" = "http://ww3.sinaimg.cn/thumbnail/006aewtbgw1ex7mpvh8z6j30ku0kuwip.jpg";
//}
//)
